package org.fuys.etp.core.model.vo;

import lombok.Builder;
import lombok.Data;

/**
 * @projectName: fuys-etp
 * @package: org.fuys.etp.core.model.vo
 * @className: TpConfigVO
 * @author: WangJing
 * @description: 线程池配置视图类
 * @date: 2025/2/5 11:48
 * @version: 1.0
 */
@Data
@Builder
public class TpConfigVO {
    private TpBaseConfigVO baseConfig;
    private TpDynamicConfigVO dynamicConfig;
    private TpFixedConfigVO fixedConfig;
    private Boolean needChange;
    private Integer loadLevel;

    public TpBaseConfigVO copyBaseConfig(){
        return TpBaseConfigVO.builder()
                .poolCoreSize(baseConfig.getPoolCoreSize())
                .poolMaxSize(baseConfig.getPoolMaxSize())
                .poolKeepAliveTime(baseConfig.getPoolKeepAliveTime())
                .poolAliveTimeUnit(baseConfig.getPoolAliveTimeUnit())
                .workQueueSize(baseConfig.getWorkQueueSize())
                .selfCheckInterval(baseConfig.getSelfCheckInterval())
                .selfCheckIntervalUnit(baseConfig.getSelfCheckIntervalUnit())
                .rejectHandleBean(baseConfig.getRejectHandleBean())
                .rejectCheckThreshold(baseConfig.getRejectCheckThreshold())
                .rejectAlertThreshold(baseConfig.getRejectAlertThreshold())
                .cpuPointLimit(baseConfig.getCpuPointLimit())
                .memoryPointLimit(baseConfig.getMemoryPointLimit())
                .description(baseConfig.getDescription())
                .build();
    }

    public TpFixedConfigVO copyFixedConfig(){
        if(this.fixedConfig == null){
            return null;
        }
        return TpFixedConfigVO.builder()
                .fixedVersion(fixedConfig.getFixedVersion())
                .loadRating(fixedConfig.getLoadRating())
                .scaleNumType(fixedConfig.getScaleNumType())
                .scaleCompareType(fixedConfig.getScaleCompareType())
                .scaleNum(fixedConfig.getScaleNum())
                .expansionNumType(fixedConfig.getExpansionNumType())
                .expansionCompareType(fixedConfig.getExpansionCompareType())
                .expansionNum(fixedConfig.getExpansionNum())
                .baseConfigVersion(fixedConfig.getBaseConfigVersion())
                .build();
    }

    public TpDynamicConfigVO copyDynamicConfig(){
        if(this.dynamicConfig == null){
            return null;
        }
        return TpDynamicConfigVO.builder()
                .dynamicVersion(dynamicConfig.getDynamicVersion())
                .maxCoreThreadStep(dynamicConfig.getMaxCoreThreadStep())
                .maxMaxThreadStep(dynamicConfig.getMaxMaxThreadStep())
                .maxQueueSizeStep(dynamicConfig.getMaxQueueSizeStep())
                .windowsChangeTrend(dynamicConfig.getWindowsChangeTrend())
                .pidKp(dynamicConfig.getPidKp())
                .pidKi(dynamicConfig.getPidKi())
                .pidKd(dynamicConfig.getPidKd())
                .pidTarget(dynamicConfig.getPidTarget())
                .baseConfigVersion(dynamicConfig.getBaseConfigVersion())
                .loadLevel(dynamicConfig.getLoadLevel())
                .windowsSize(dynamicConfig.getWindowsSize())
                .windowMinSize(dynamicConfig.getWindowMinSize())
                .windowWeights(dynamicConfig.getWindowWeights())
                .build();
    }

    public TpConfigVO copyConfig(){
        return TpConfigVO.builder()
                .baseConfig(copyBaseConfig())
                .dynamicConfig(copyDynamicConfig())
                .fixedConfig(copyFixedConfig())
                .build();
    }

}
